{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 准备工作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import json\n",
    "import pandas as pd\n",
    "API_key = \"2d015ae1da99945790f1601af060c108\"\n",
    "home_location = \"113.231875,23.136425\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 行政区域查询"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'count': '1',\n",
       " 'suggestion': {'keywords': [], 'cities': []},\n",
       " 'districts': [{'citycode': '020',\n",
       "   'adcode': '440100',\n",
       "   'name': '广州市',\n",
       "   'center': '113.280637,23.125178',\n",
       "   'level': 'city',\n",
       "   'districts': []}]}"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "url_geo1 = \"https://restapi.amap.com/v3/config/district?parameters\"\n",
    "params_geo1 = {\n",
    "    \"key\": API_key, \n",
    "    \"keywords\": \"广州\",\n",
    "    \"subdistrict\": 0\n",
    "}\n",
    "response = requests.get(url = url_geo1, params = params_geo1)\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 搜索POI"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'suggestion': {'keywords': [], 'cities': []},\n",
       " 'count': '6',\n",
       " 'infocode': '10000',\n",
       " 'pois': [{'parent': [],\n",
       "   'address': '温泉大道882号',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': '3.5'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '科教文化服务;学校;高等院校',\n",
       "   'photos': [{'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/6cb6683be58d514bc02a80c1dbd2ff05'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/ca4a133bec5f0f26fd4d6d694c25d10f'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/83c34f0b230b189a03ea87dc42c728c3'}],\n",
       "   'typecode': '141201',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': '中山大学南方学院',\n",
       "   'location': '113.679262,23.632583',\n",
       "   'tel': '020-61787331',\n",
       "   'shopid': [],\n",
       "   'id': 'B00140MR9A'},\n",
       "  {'parent': [],\n",
       "   'address': '温泉镇',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': []},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '科教文化服务;学校;高等院校',\n",
       "   'photos': [],\n",
       "   'typecode': '141201',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': '中山大学南方学院',\n",
       "   'location': '113.671493,23.643831',\n",
       "   'tel': [],\n",
       "   'shopid': [],\n",
       "   'id': 'B0FFMCZOK0'},\n",
       "  {'parent': 'B00140MR9A',\n",
       "   'address': '博学路7',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': []},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '科教文化服务;学校;高等院校',\n",
       "   'photos': [],\n",
       "   'typecode': '141201',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': '309',\n",
       "   'adname': '从化区',\n",
       "   'name': '中山大学南方学院教学楼7号',\n",
       "   'location': '113.678600,23.633330',\n",
       "   'tel': [],\n",
       "   'shopid': [],\n",
       "   'id': 'B00141TQGR'},\n",
       "  {'parent': 'B00140MR9A',\n",
       "   'address': '南方学院东北',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': []},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '科教文化服务;学校;高等院校',\n",
       "   'photos': [],\n",
       "   'typecode': '141201',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': '309',\n",
       "   'adname': '从化区',\n",
       "   'name': '中山大学南方学院12BLOCK',\n",
       "   'location': '113.682608,23.636598',\n",
       "   'tel': [],\n",
       "   'shopid': [],\n",
       "   'id': 'B0FFLJV95W'},\n",
       "  {'parent': 'B00140MR9A',\n",
       "   'address': '博学路7号附近',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': []},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '科教文化服务;学校;高等院校',\n",
       "   'photos': [],\n",
       "   'typecode': '141201',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': '309',\n",
       "   'adname': '从化区',\n",
       "   'name': '中山大学南方学院惟贤门',\n",
       "   'location': '113.678437,23.633721',\n",
       "   'tel': [],\n",
       "   'shopid': [],\n",
       "   'id': 'B0FFKERBQZ'},\n",
       "  {'parent': [],\n",
       "   'address': [],\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': []},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '科教文化服务;学校;高等院校',\n",
       "   'photos': [],\n",
       "   'typecode': '141201',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': '中山大学南方学院教学楼1号',\n",
       "   'location': '113.677077,23.631783',\n",
       "   'tel': [],\n",
       "   'shopid': [],\n",
       "   'id': 'B0G3ARGF5Y'}],\n",
       " 'status': '1',\n",
       " 'info': 'OK'}"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "url_geo2 = \"https://restapi.amap.com/v3/place/text?parameters\"\n",
    "params_geo2 = {\n",
    "    \"key\": API_key, \n",
    "    \"keywords\": \"中山大学南方学院\",\n",
    "    \"types\": \"高等院校\"\n",
    "}\n",
    "response = requests.get(url = url_geo2, params = params_geo2)\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## IP定位"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'province': '广东省',\n",
       " 'city': '广州市',\n",
       " 'adcode': '440100',\n",
       " 'rectangle': '113.1017375,22.93212254;113.6770499,23.3809537'}"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "url_geo3 = \"https://restapi.amap.com/v3/ip?parameters\"\n",
    "params_geo3= {\"key\": API_key, }\n",
    "response = requests.get(url = url_geo3, params = params_geo3)\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 批量请求接口"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '0', 'info': 'INVALID_BATCH_PARAM', 'infocode': '20005'}"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "url_geo4 = \"https://restapi.amap.com/v3/batch?key=2d015ae1da99945790f1601af060c108\"\n",
    "response = requests.get(url = url_geo4)\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 静态地图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'https://restapi.amap.com/v3/staticmap?parameters&key=2d015ae1da99945790f1601af060c108&location=113.231875%2C23.136425&zoom=15'"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "url_geo5 = \"https://restapi.amap.com/v3/staticmap?parameters\"\n",
    "params_geo5 = {\n",
    "    \"key\": API_key, \n",
    "    \"location\": \"113.231875,23.136425\", \n",
    "    \"zoom\": \"15\",\n",
    "}\n",
    "response = requests.get(url = url_geo5, params = params_geo5)\n",
    "response.url"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在浏览器中打开获得以下的图象\n",
    "![](https://restapi.amap.com/v3/staticmap?parameters&key=2d015ae1da99945790f1601af060c108&location=113.231875%2C23.136425&zoom=15)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 坐标转换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'info': 'ok',\n",
       " 'infocode': '10000',\n",
       " 'locations': '113.237203233507,23.133752441407'}"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "url_geo6 = \"https://restapi.amap.com/v3/assistant/coordinate/convert?parameters\"\n",
    "params_geo6 = {\n",
    "    \"key\": API_key, \n",
    "    \"locations\": home_location,\n",
    "    \"coordsys\": \"gps\"\n",
    "}\n",
    "response = requests.get(url = url_geo6, params = params_geo6)\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 天气查询"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'count': '1',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'lives': [{'province': '广东',\n",
       "   'city': '广东省',\n",
       "   'adcode': '440000',\n",
       "   'weather': '晴',\n",
       "   'temperature': '23',\n",
       "   'winddirection': '东',\n",
       "   'windpower': '≤3',\n",
       "   'humidity': '86',\n",
       "   'reporttime': '2020-11-17 21:22:24'}]}"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "url_geo7 = \"https://restapi.amap.com/v3/weather/weatherInfo?parameters\"\n",
    "params_geo7 = {\n",
    "    \"key\": API_key, \n",
    "    \"city\": \"440000\"\n",
    "}\n",
    "response = requests.get(url = url_geo7, params = params_geo7)\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 输入提示"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'count': '10',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'tips': [{'id': [],\n",
       "   'name': '麦当劳',\n",
       "   'district': [],\n",
       "   'adcode': [],\n",
       "   'location': [],\n",
       "   'address': [],\n",
       "   'typecode': [],\n",
       "   'city': []},\n",
       "  {'id': 'B0FFIPDFJM',\n",
       "   'name': '麦当劳',\n",
       "   'district': '广东省广州市海珠区',\n",
       "   'adcode': '440105',\n",
       "   'location': '113.273536,23.102431',\n",
       "   'address': [],\n",
       "   'typecode': '050302',\n",
       "   'city': []},\n",
       "  {'id': 'B0G23OGLFV',\n",
       "   'name': '麦当劳',\n",
       "   'district': '广东省广州市荔湾区',\n",
       "   'adcode': '440103',\n",
       "   'location': '113.208276,23.115950',\n",
       "   'address': '芳村大道67号1北60米',\n",
       "   'typecode': '050300',\n",
       "   'city': []},\n",
       "  {'id': 'B0FFHM6L0X',\n",
       "   'name': '麦当劳',\n",
       "   'district': '广东省广州市荔湾区',\n",
       "   'adcode': '440103',\n",
       "   'location': '113.247799,23.124335',\n",
       "   'address': '康王中路486和业广场2楼',\n",
       "   'typecode': '050302',\n",
       "   'city': []},\n",
       "  {'id': 'B00140WDOP',\n",
       "   'name': '麦当劳(敦和店)',\n",
       "   'district': '广东省广州市海珠区',\n",
       "   'adcode': '440105',\n",
       "   'location': '113.316483,23.089556',\n",
       "   'address': '敦和路59号敦煌商业城1-2层',\n",
       "   'typecode': '050302',\n",
       "   'city': []},\n",
       "  {'id': 'B00140NHRH',\n",
       "   'name': '麦当劳(沙河店)',\n",
       "   'district': '广东省广州市天河区',\n",
       "   'adcode': '440106',\n",
       "   'location': '113.310785,23.151119',\n",
       "   'address': '先烈东路296号沙河宾馆1层',\n",
       "   'typecode': '050302',\n",
       "   'city': []},\n",
       "  {'id': 'B00140UEPI',\n",
       "   'name': '麦当劳(中唱大厦店)',\n",
       "   'district': '广东省广州市白云区',\n",
       "   'adcode': '440111',\n",
       "   'location': '113.263211,23.156595',\n",
       "   'address': '机场路25号中唱大厦1层',\n",
       "   'typecode': '050302',\n",
       "   'city': []},\n",
       "  {'id': 'B0FFLJ1TJM',\n",
       "   'name': '麦当劳(龙归城分店)',\n",
       "   'district': '广东省广州市白云区',\n",
       "   'adcode': '440111',\n",
       "   'location': '113.321992,23.276948',\n",
       "   'address': '太和镇龙悦新街156号悦和方首层',\n",
       "   'typecode': '050302',\n",
       "   'city': []},\n",
       "  {'id': 'B00141JJIT',\n",
       "   'name': '麦当劳(棠溪店)',\n",
       "   'district': '广东省广州市白云区',\n",
       "   'adcode': '440111',\n",
       "   'location': '113.250813,23.179885',\n",
       "   'address': '三元里大道1231鸿盛商业城1-2层',\n",
       "   'typecode': '050302',\n",
       "   'city': []},\n",
       "  {'id': 'B00141IEMO',\n",
       "   'name': '麦当劳(钟村店)',\n",
       "   'district': '广东省广州市番禺区',\n",
       "   'adcode': '440113',\n",
       "   'location': '113.314455,22.978467',\n",
       "   'address': '105国道商会大厦1-2层',\n",
       "   'typecode': '050302',\n",
       "   'city': []}]}"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "url_geo8 = \"https://restapi.amap.com/v3/assistant/inputtips?parameters\"\n",
    "params_geo8 = {\n",
    "    \"key\":API_key, \n",
    "    \"keywords\": \"麦当劳\",\n",
    "    \"city\": \"020\"\n",
    "}\n",
    "response = requests.get(url = url_geo8, params = params_geo8)\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 交通态势"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 官网不给新用户使用并且逐渐取消这一个API接口"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'info': 'INSUFFICIENT_PRIVILEGES',\n",
       " 'infocode': '10012',\n",
       " 'status': '0',\n",
       " 'sec_code_debug': 'd41d8cd98f00b204e9800998ecf8427e',\n",
       " 'key': '2d015ae1da99945790f1601af060c108',\n",
       " 'sec_code': 'd41d8cd98f00b204e9800998ecf8427e'}"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "url_geo9 = \"https://restapi.amap.com/v3/traffic/status/rectangle?parameters\"\n",
    "params_geo9 = {\n",
    "    \"key\": API_key, \n",
    "    \"rectangle\": \"116.351147,39.966309;116.357134,39.968727\",\n",
    "}\n",
    "response = requests.get(url = url_geo9, params = params_geo9)\n",
    "response.json()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
